package com.xmb.wechat.delegate;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;

import com.blankj.utilcode.util.SizeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.nil.sdk.utils.DateUtils;
import com.xmb.wechat.R;
import com.xmb.wechat.baserecyclerview.BaseRecyclerViewManager;
import com.xmb.wechat.common.Constant;
import com.xmb.wechat.bean.PayProofBean;
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;

import java.util.ArrayList;
import java.util.Date;

/**
 * @Author lijiangop
 * @CreateTime 2020/4/20 17:54
 */
public class PayProofDelegate extends BaseRecyclerViewManager {

    public PayProofDelegate(Activity activity) {
        super(activity);
    }

    @Override
    public BaseQuickAdapter initAdapter() {
        return new BaseQuickAdapter<PayProofBean, BaseViewHolder>(R.layout.item_pay_proof, new ArrayList<>()) {
            @SuppressLint("SimpleDateFormat")
            @Override
            protected void convert(BaseViewHolder helper, PayProofBean item) {
                helper.setText(R.id.tv_type, TextUtils.isEmpty(item.getTypeName()) ? "" : item.getTypeName());
                helper.setText(R.id.tv_time, DateUtils.getStringByFormat(new Date(item.getMsgTime()), "yyyy-MM-dd HH:mm"));
                String value = "";
                switch (item.getType()) {
                    case Constant.PayProofType.TYPE_WITHDRAW_START:
                    case Constant.PayProofType.TYPE_WITHDRAW_FINISH:
                    case Constant.PayProofType.TYPE_PAY_PROOF_GR:
                    case Constant.PayProofType.TYPE_PAY_PROOF_SH:
                        value = TextUtils.isEmpty(item.getMoney()) ? "" : "-" + item.getMoney();
                        break;
                    case Constant.PayProofType.TYPE_QRCODE_FINISH_NOTIFICATION:
                        value = TextUtils.isEmpty(item.getMoney()) ? "" : "+" + item.getMoney();
                        break;
                }
                helper.setText(R.id.tv_money, value);
                helper.getView(R.id.iv_delete).setOnClickListener(v -> {
                    mData.remove(item);
                    notifyDataSetChanged();
                });
            }
        };
    }

    @Override
    protected RecyclerView.ItemDecoration getItenDecoration() {
        return new HorizontalDividerItemDecoration.Builder(context).size(SizeUtils.dp2px(0.5f)).color(ContextCompat.getColor(context, R.color.black_10)).build();
    }
}
